﻿#region Copyright 2008 - Evolution Systems.
//
// Author: José Rogério Ferreira dos Santos(joserogerio.santos@gmail.com)
// Date: 27/05/2009
// Time: 18:10
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, eletronic, mechanical or otherwise, is prohibited
// without the prior written permission of the author.
//
// Filename: ${FILE_NAME}.cs
#endregion

using System;
using System.Collections.Generic;

namespace csharp.rad.finan
{
	/// <summary>
	/// Description of Bpr.
	/// </summary>
	public class Bpr: common.DefaultClass, common.IClass
	{
		#region private declarations
			private string _document_number;
			private string _bank_number;
			private string _create_date;
			private string _create_hour;
			private string _emission_date;
			private string _perc_juros;
			private string _perc_discount;
			private string _perc_penalty;
			private string _penalty_after_days;
			private string _forecast;
			private string _projection;
			private string _value;
			private string _discount;
			private string _discount_until;
			private string _historic;
			private string _obs;
			private string _person_id;
			private string _company_id;
			private string _status_id;
			private string _bill_id;
			private string _document_type_id;
			private string _collection_type_id;
			private string _user_id;
			private string _cost_center_id;
			private string _bill_mvt_id;
			private string _type;	
			private string _first_expiration_date;
		#endregion
		
		#region properties
		public string documentNumber 
		{
			get { return _document_number; }
			set { _document_number = value; }
		}
		
		public string bankNumber 
		{
			get { return _bank_number; }
			set { _bank_number = value; }
		}
		
		public string createDate 
		{
			get { return _create_date; }
			set { _create_date = value; }
		}
		
		public string createHour 
		{
			get { return _create_hour; }
			set { _create_hour = value; }
		}
		
		public string emissionDate 
		{
			get { return _emission_date; }
			set { _emission_date = value; }
		}
		
		public string percJuros 
		{
			get { return _perc_juros; }
			set { _perc_juros = value; }
		}
		
		public string percDiscount 
		{
			get { return _perc_discount; }
			set { _perc_discount = value; }
		}
		
		public string percPenalty 
		{
			get { return _perc_penalty; }
			set { _perc_penalty = value; }
		}
		
		public string penaltyAfterDays 
		{
			get { return _penalty_after_days; }
			set { _penalty_after_days = value; }
		}
		
		public string forecast 
		{
			get { return _forecast; }
			set { _forecast = value; }
		}
		
		public string projection 
		{
			get { return _projection; }
			set { _projection = value; }
		}
		
		public string value 
		{
			get { return _value; }
			set { _value = value; }
		}
		
		public string discount 
		{
			get { return _discount; }
			set { _discount = value; }
		}
		
		public string discountUntil 
		{
			get { return _discount_until; }
			set { _discount_until = value; }
		}
		
		public string historic 
		{
			get { return _historic; }
			set { _historic = value; }
		}
		
		public string obs 
		{
			get { return _obs; }
			set { _obs = value; }
		}
		
		public string personId 
		{
			get { return _person_id; }
			set { _person_id = value; }
		}
		
		public string companyId 
		{
			get { return _company_id; }
			set { _company_id = value; }
		}
		
		public string statusId 
		{
			get { return _status_id; }
			set { _status_id = value; }
		}
		
		public string billId 
		{
			get { return _bill_id; }
			set { _bill_id = value; }
		}
		
		public string documentTypeId 
		{
			get { return _document_type_id; }
			set { _document_type_id = value; }
		}
		
		public string collectionTypeId 
		{
			get { return _collection_type_id; }
			set { _collection_type_id = value; }
		}
		
		public string userId 
		{
			get { return _user_id; }
			set { _user_id = value; }
		}
		
		public string costCenterId 
		{
			get { return _cost_center_id; }
			set { _cost_center_id = value; }
		}
		
		public string billMvtId
		{
			get { return _bill_mvt_id; }
			set { _bill_mvt_id = value; }
		}
		
		public string type 
		{
			get { return _type; }
			set { _type = value; }
		}
		
		public string firstExpirationDate
		{
			get { return _first_expiration_date; }
			set { _first_expiration_date = value; }
		}
			
		#endregion
		
		public Bpr()
		{
			gsql.table = "finan.bpr";
			_sequence  = "finan.bpr_bpr_id_seq";     
			clear();
		}
		
		public void clear()
		{
			 _id 					= string.Empty;
			 _document_number 		= string.Empty;
			 _bank_number 			= string.Empty;
			 _create_date 			= string.Empty;
			 _create_hour 			= string.Empty;
			 _emission_date 		= string.Empty;
			 _perc_juros 			= string.Empty;
			 _perc_discount 		= string.Empty;
			 _perc_penalty 			= string.Empty;
			 _penalty_after_days 	= string.Empty;
			 _forecast 				= string.Empty;
			 _projection 			= string.Empty;
			 _value 				= string.Empty;
			 _discount		 		= string.Empty;
			 _discount_until 		= string.Empty;
			 _historic 				= string.Empty;
			 _obs 					= string.Empty;
			 _person_id 			= string.Empty;
			 _company_id 			= string.Empty;
			 _status_id 			= string.Empty;
			 _bill_id 				= string.Empty;
			 _document_type_id 		= string.Empty;
			 _collection_type_id 	= string.Empty;
			 _user_id 				= string.Empty;
			 _cost_center_id 		= string.Empty;
			 _bill_mvt_id			= string.Empty;
			 _type 					= string.Empty; 	
			 _first_expiration_date = string.Empty;
		}
		
		public override void get(System.Data.DataRow dr)
		{
			_id 					= dr["bpr_id"].ToString();
			_document_number 		= dr["bpr_document_number"].ToString();
			_bank_number 			= dr["bpr_bank_number"].ToString();
			_create_date 			= Convert.ToDateTime(dr["bpr_create_date"]).ToString(common.CONSTANTS.dateFormatBrazilian);
			_create_hour 			= dr["bpr_create_hour"].ToString();
			_emission_date 			= Convert.ToDateTime(dr["bpr_emission_date"]).ToString(common.CONSTANTS.dateFormatBrazilian);
			_perc_juros 			= dr["bpr_perc_juros"].ToString();
			_perc_discount 			= dr["bpr_perc_discount"].ToString();
			_perc_penalty 			= dr["bpr_perc_penalty"].ToString();
			_penalty_after_days 	= dr["bpr_penalty_after_days"].ToString();
			_forecast 				= dr["bpr_forecast"].ToString();
			_projection 			= dr["bpr_projection"].ToString();
			_value 					= dr["bpr_value"].ToString();
			_discount 				= dr["bpr_discount"].ToString();
			_discount_until 		= dr["bpr_discount_until"].ToString();
			_historic 				= dr["bpr_historic"].ToString();
			_obs 					= dr["bpr_obs"].ToString();
			_person_id 				= dr["bpr_person_id"].ToString();
			_company_id 			= dr["bpr_company_id"].ToString();
			_status_id 				= dr["bpr_status_id"].ToString();
			_bill_id 				= dr["bpr_bill_id"].ToString();
			_document_type_id 		= dr["bpr_document_type_id"].ToString();
			_collection_type_id 	= dr["bpr_collection_type_id"].ToString();
			_user_id 				= dr["bpr_user_id"].ToString();
			_cost_center_id 		= dr["bpr_cost_center_id"].ToString();
			_bill_mvt_id			= dr["bpr_bill_mvt_id"].ToString();
			_type             		= dr["bpr_type"].ToString();    
			_first_expiration_date 	= Convert.ToDateTime(dr["bpr_first_expiration_date"]).ToString(common.CONSTANTS.dateFormatBrazilian);
		}
		
		public override void setGsql()
		{
			gsql.setValue(_id 						,"bpr_id");
			gsql.setValue(_document_number 	    	,"bpr_document_number");
			gsql.setValue(_bank_number 		    	,"bpr_bank_number");
			gsql.setAsDateTime(_create_date 		,"bpr_create_date");
			gsql.setValue(_create_hour 		    	,"bpr_create_hour");
			gsql.setAsDateTime(_emission_date 	    ,"bpr_emission_date");
			gsql.setAsDouble(_perc_juros 			,"bpr_perc_juros");
			gsql.setAsDouble(_perc_discount 		,"bpr_perc_discount");
			gsql.setAsDouble(_perc_penalty 			,"bpr_perc_penalty");
			gsql.setValue(_penalty_after_days   	,"bpr_penalty_after_days");
			gsql.setValue(_forecast 				,"bpr_forecast");
			gsql.setValue(_projection 		    	,"bpr_projection");
			gsql.setAsDouble(_value 				,"bpr_value");
			gsql.setAsDouble(_discount 				,"bpr_discount");
			gsql.setAsDateTime(_discount_until  	,"bpr_discount_until");
			gsql.setValue(_historic 				,"bpr_historic");
			gsql.setValue(_obs 						,"bpr_obs");
			gsql.setValue(_person_id 				,"bpr_person_id");
			gsql.setValue(_company_id 		    	,"bpr_company_id");
			gsql.setValue(_status_id 				,"bpr_status_id");
			gsql.setValue(_bill_id 			    	,"bpr_bill_id");
			gsql.setValue(_document_type_id     	,"bpr_document_type_id");
			gsql.setValue(_collection_type_id   	,"bpr_collection_type_id");
			gsql.setValue(_user_id 			    	,"bpr_user_id");
			gsql.setValue(_cost_center_id 	    	,"bpr_cost_center_id");
			gsql.setValue(_bill_mvt_id				,"bpr_bill_mvt_id");
			gsql.setValue(_type                 	,"bpr_type");
		}	
	}
    
	public class Bprs : common.DefaultList, common.IList
	{
		public Bprs()
		{
			gsql.table = "finan.bpr";
		}
		
		public Bpr get(Int32 index)
		{
			return (Bpr)items[index];
		}
		
		public Bpr get()
		{
			return (Bpr)items[index];
		}		
		
		public bool fillList()
		{
			gsql.prepare();
			gsql.setValue("","*");
			
			return mountList();
		}
		
		public bool fillListToPay(string beginDate, string endDate, string description)
		{
			gsql.prepare();
			gsql.setValue("","*");
			gsql.conditionalWhere = "bpr_type = 'D'";
			gsql.conditionalWhere = "bpr_emission_date BETWEEN '"+
									Convert.ToDateTime(beginDate).ToString(common.CONSTANTS.dateFormatInternational)+
									"' AND '"+
									Convert.ToDateTime(endDate).ToString(common.CONSTANTS.dateFormatInternational)+"'";
			gsql.conditionalWhere = "bpr_historic LIKE '%"+description+"%'";
			gsql.additionalWhere  = "ORDER BY bpr_emission_date";			
			
			return mountList();
		}
		
		public bool fillListToReceyce(string beginDate, string endDate, string description)
		{
			gsql.prepare();
			gsql.setValue("","*");
			gsql.conditionalWhere = "bpr_type = 'C'";
			gsql.conditionalWhere = "bpr_emission_date BETWEEN '"+
									Convert.ToDateTime(beginDate).ToString(common.CONSTANTS.dateFormatInternational)+
									"' AND '"+
									Convert.ToDateTime(endDate).ToString(common.CONSTANTS.dateFormatInternational)+"'";
			gsql.conditionalWhere = "bpr_historic LIKE '%"+description+"%'";
			gsql.additionalWhere  = "ORDER BY bpr_emission_date";
			
			return mountList();
		}
		
		private bool mountList()
		{
			Int32 tam;
			
			if (!gsql.execute())
				return false;
			
			tam = gsql.getRowCount();
			items.Clear();
			for (int i=0; i < tam; i++)
			{
				Bpr aux = new Bpr();
				aux.get(gsql.getRow(i));
				items.Add(aux);
			}
			return true;
		}
	}		
}
